# coding=utf8
# 检查资源端口是否重复

from app import create_app
from app.modules.apps.models import AppInfo

application = create_app(flask_config = 'local')


def main(_env_name):
    with application.app_context():
        _list = AppInfo.query.filter_by(env_name = _env_name).all()
        for _app in _list:
            _l = AppInfo.query.filter_by(env_name = _env_name, host = _app.host, http_port = _app.http_port).all()
            if len(_l) != 1:
                for _a in _l:
                    print 'http:%s' % _a.to_dict()
            if _app.entrance_type == 'jmx':
                _l = AppInfo.query.filter_by(env_name = _env_name, host = _app.host, jmx_port = _app.jmx_port).all()
                if len(_l) != 1:
                    for _a in _l:
                        print 'jmx:%s' % _a.to_dict()
        pass


if __name__ == '__main__':
    _env_name = 'online'
    main(_env_name)
